columnviewlayout: Handle for_size propertly
authorMatthias Clasen <mclasen@redhat.com>
Fri, 5 Jun 2020 15:34:51 +0000 (11:34 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 5 Jun 2020 17:27:50 +0000 (13:27 -0400)
When we are given a for_size as width for the whole
column view, we need to distribute it over the columns
as gtk_column_view_allocate_columns would, in order
to find out which for_size to give to each cell.

This is a bit recursive, but works. Since we are
doing this recursion for every row, we should consider
adding a cache for those distributed widths.

gtk/gtkcolumnviewlayout.c

index 44d99df6739fd126a4e9d8c82d9764a37e1f0227..1b56a3b6ff822df3ed16d7c1387bce1f4ce5d5d8 100644 (file)
@@ -47,10 +47,19 @@ gtk_column_view_layout_measure_along (GtkColumnViewLayout *self,
 {
   GtkOrientation orientation = GTK_ORIENTATION_VERTICAL;
   GtkWidget *child;
+  guint i, n;
+  GtkRequestedSize *sizes = NULL;
 
-  for (child = _gtk_widget_get_first_child (widget);
+  if (for_size > -1)
+    {
+      n = g_list_model_get_n_items (gtk_column_view_get_columns (self->view));
+      sizes = g_newa (GtkRequestedSize, n);
+      gtk_column_view_distribute_width (self->view, for_size, sizes);
+    }
+
+  for (child = _gtk_widget_get_first_child (widget), i = 0;
        child != NULL;
-       child = _gtk_widget_get_next_sibling (child))
+       child = _gtk_widget_get_next_sibling (child), i++)
     {
       int child_min = 0;
       int child_nat = 0;
@@ -60,7 +69,8 @@ gtk_column_view_layout_measure_along (GtkColumnViewLayout *self,
       if (!gtk_widget_should_layout (child))
         continue;
 
-      gtk_widget_measure (child, orientation, for_size,
+      gtk_widget_measure (child, orientation,
+                          for_size > -1 ? sizes[i].minimum_size : -1,
                           &child_min, &child_nat,
                           &child_min_baseline, &child_nat_baseline);